<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
    }

    public function index()
    {
        layout(false);

        if(!empty($_POST)){
            $verify = I('param.verify','');
            if(!check_verify($verify)){
                $this->error("亲，验证码输错了哦！");
            }else{
                $name=I('post.name');
                $stuid=I('post.stuid');

                $ret=D('StuInfo');
                $tmp=$ret->checkUser($name,$stuid);

                if($tmp==1){

                    $dataInfo=array(
                        "name"=>$name,
                        "stuid"=>$stuid
                    );
                    session("dataInfo",$dataInfo);
                    $this->redirect('Home/home');
                }else if($tmp==0){
                    $this->error('密码错误');
                }else{
                    $this->error('帐号不存在');
                }
            }

        }


        $this->display();
    }

    public function logout(){

        session('dataInfo',null);

        $this->success('退出成功！', U('Home/Index/index'));
    }

    public function verify_c(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = '0123456789';
        $Verify->imageW = 130;
        $Verify->imageH = 50;
        //$Verify->expire = 600;
        $Verify->entry();
    }


}